Column

Column

Total Locations Found:

Map Filters






Data provided by the New York State Office of Mental Health and found publicly on DATA.NY.GOV

Example created by Meghan Harris with the flexdashboard, Crosstalk, SummaryWidget, and DT packages.

---
title: "New York State's (Brooklyn,NY) Local Mental Health Programs"
output:
  flexdashboard::flex_dashboard:
    source_code: embed
    css: nycmhstyle.css
    
---

```{r setup, include=FALSE}


#Library install and load in.#
`Required Packages` <- c("flexdashboard","knitr","purrr","readr","tidyverse","extrafont","leaflet","leafem","crosstalk","DT","summarywidget","sp","raster") 
`New Packages` <- `Required Packages`[!(`Required Packages` %in% installed.packages()[,"Package"])]
if(length(`New Packages`)) install.packages(`New Packages`)
invisible(suppressPackageStartupMessages(suppressWarnings(lapply(`Required Packages`, require, character.only=T))))


#Loading the datasets into the environment.#
#MH programs with geocodes#
MHprograms <- readRDS("Data/MHprogramsNYC.RDS")


#Converting data frames into shared data objects with crosstalk. This will allow the map, filters, and tables to be interactive and dynamic.#
Sharedgeodata <- SharedData$new(MHprograms)


```

Column {data-width=750}
-----------------------------------------------------------------------

### 

```{r map}

#Pulling a "Home" icon I've hosted on the internet===
Homeimg <- htmltools::HTML(paste(""))

#Naming the home image for the addhomebutton function in the leaflet map===
Home <- list("Home" = Homeimg)

#Generating a bounding box of the entire data set. This will act as our "homebase" to zoom back to when the home button is clicked on===
homebase <- ggmap::make_bbox(lon, lat, data = MHprograms)

# Retrieving the center point for the map data to set the "home" view===
coordinates(MHprograms) <- ~lon+lat
proj4string(MHprograms) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
mapcenter <- coordinates(as(extent(MHprograms), "SpatialPolygons"))

#Creating the leaflet map from the shared geo data object===
Sharedgeodata %>%
  leaflet() %>%
  addProviderTiles(providers$OpenStreetMap) %>%
  addAwesomeMarkers(
    popup = ~paste0(
      "

",MHprograms$`Agency Name`, "


", "

",MHprograms$`Program Name`,"


", "Phone: ",MHprograms$`Agency Phone`, "
", MHprograms$`Program Address 1`, "
", MHprograms$City, MHprograms$`Program State`, MHprograms$`Program Zip`), icon = awesomeIcons( library = "fa", icon = ifelse( test = MHprograms$`Program Category Description` == "Outpatient", yes = "fa-stethoscope", no = ifelse( test = MHprograms$`Program Category Description` == "Inpatient", yes = "fa-bed", no = ifelse( test = MHprograms$`Program Category Description` == "Emergency", yes = "fa-ambulance", no = "fa-users" ))), iconColor = "#ffffff", markerColor = "darkpurple")) %>% addHomeButton(ext = homebase, group = Home, position = "topright", add = TRUE) %>% setView(lng = mapcenter[1] , lat = mapcenter[2], zoom = 12) ``` Column {data-width=250} ----------------------------------------------------------------------- ### {data-height=170}

Total Locations Found:

`r summarywidget(Sharedgeodata, statistic='count', digits=0)`

### {data-height=230} ```{r datatable} Sharedgeodata %>% DT::datatable( extensions = c("Scroller"), rownames = FALSE, style = "bootstrap", class = "compact", selection = list(mode = "multiple"), options = list( dom = "Btip", deferRender = TRUE, scroller = FALSE, fillContainer = TRUE, columnDefs = list( list(width = '50%', visible = FALSE, targets = c(0,4:13,15:16))), colnames = c( "Location Name" = "Program Name", "Ages Served" = "Populations Served", "Phone Number" = "Program Phone", "Address" = "Complete Address" ))) ``` ### {data-height=650}

Map Filters


```{r mapfilters} filter_checkbox( id = "Program Category Description", label = "Program Type", sharedData = Sharedgeodata, group = ~`Program Category Description`, allLevels = FALSE, inline = TRUE ) ```
```{r mapfilters2} filter_select( id = "Program Subcategory Description", label = "Program Setting", sharedData = Sharedgeodata, group = ~`Program Subcategory Description`, allLevels = FALSE ) ``` ```{r mapfilters3} filter_select( id = "Populations Served", label = "Ages Served", sharedData = Sharedgeodata, group = ~`Populations Served`, allLevels = FALSE ) ``` ```{r mapfilters4} filter_select( id = "Program Zip", label = "Zip Code", sharedData = Sharedgeodata, group = ~`Program Zip`, allLevels = FALSE ) ```



Data provided by the New York State Office of Mental Health and found publicly on DATA.NY.GOV

Example created by Meghan Harris with the flexdashboard, Crosstalk, SummaryWidget, and DT packages.